package com.uifp.gradebook;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import com.uifp.gradebook.adaptors.*;

import com.uifp.gradebook.business_objects.Class;

public class VSCActualFragment extends Fragment  {
	private int classID = 0;

    public void onCreate(Bundle state) {
	    super.onCreate(state);
	    final Bundle args = getArguments();
	    classID = args.getInt("CLASS_ID");
	}
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
 
        View rootView = inflater.inflate(R.layout.fragment_actual, container, false);
 
        return rootView;
    }

	
	public void onActivityCreated(Bundle savedInstanceState) {  
        super.onActivityCreated(savedInstanceState); 
        
        ListView listView = (ListView) getView().findViewById(R.id.actual_grades_listview);  

        final Bundle args = getArguments();
        classID = args.getInt("CLASS_ID");
    	if(savedInstanceState != null){
    	    classID = savedInstanceState.getInt("CLASS_ID", 0);
    	}
		if(classID != 0){
			DataBaseHelper dbHelper = new DataBaseHelper(getActivity());
			Class thisClass = dbHelper.getClassByID(classID);
			thisClass.suffixLabels();
			
		    GradesArrayAdaptor adapter = new GradesArrayAdaptor(getActivity(), R.layout.grade_item, thisClass.getGradeList());
		    listView.setAdapter(adapter);

		}
	}
  }